package com.yanqu.road.server.logic.activity.condition.recharge;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.config.goods.GetRechargeMallResult;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.ActivityModule;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseActivityCondition;

import java.math.BigInteger;

/**
 * @author ：zfr
 * @date ：2021/12/29 10:04
 */
public class RechargeGrandChildActivityCondition extends BaseActivityCondition {

    public RechargeGrandChildActivityCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.RechargeGrandChild.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.RechargeGrandChild.getValue(), handle);
    }

    public boolean isCompleted(GamePlayer player) {
        return getValue().compareTo(activityConditionInfo.getParamList().get(3)) >= 0;
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        int args = (int)object;
        if(args > 0){
            //加道具，设置购买状态
            if(getValue().intValue() == args) {
                getRMBMallActivityReward(args);
            }
        }else {
            if (getValue().compareTo(BigInteger.ZERO) == 0) {
                GetRechargeMallResult result = player.getModule(ActivityModule.class).getShowRMBMallInfo(activityConditionInfo);
                if (result.isDuringCd() && args != -666) {
                    return;
                }
                setRMBMallActivityInfo(result.getMallInfo());
            }
        }
    }
}
